<template>
	<view>
		<view class="goods-item">
			<!-- 左侧盒子 -->
			<view class="goods-item-left">
				<radio
					@click="changeRadioSelect"
					v-if="isShowRadio" :checked="goods.goods_state"
					color="#C00000" class="goods-radio"></radio>
				<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
			</view>
			<!-- 右侧盒子 -->
			<view class="goods-item-right">
				<view class="goods-name">{{ goods.goods_name }}</view>
				<view class="goods-info-box">
					<!-- 使用过滤器处理商品价格 -->
					<view class="goods-price">￥{{ goods.goods_price | tofixed }}</view>
					<uni-number-box
						v-if="isShowNum"
						@change="changeNumber"
						:value="goods.goods_count" :min="1"></uni-number-box>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		filters: {		// 过滤器配置项
			tofixed(num){			// 处理价格过滤器
				return Number(num).toFixed(2)
			}
		},
		methods: {
			changeNumber(value){						// 处理数字框处理函数
				this.$emit('handleNumber',{
					goods_id: this.goods.goods_id,
					goods_count: value
				})
			},
			changeRadioSelect(){			// 处理单选按钮处理函数
				this.$emit('handleRadioSelect',{
					goods_id: this.goods.goods_id,
					goods_state: !this.goods.goods_state
				})
			}
		},
		data() {
			return {
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			}
		},
		props: {				// 接收父组件传递过来的数据
			isShowNum: {			// 是否展示 Num 数字框组件
				type: Boolean,
				default: false
			},
			isShowRadio: {		// 是否展示 Radio 组件
				type: Boolean,
				default: false
			},
			goods: {
				type: Object,
				default: () => ({})
			}
		},
		name:"my-goods"
	}
</script>

<style lang="scss">
.goods-item {
	display: flex;
	padding: 10px 5px;
	border-bottom: 1px solid #f0f0f0;
	width: 750rpx;
	box-sizing: border-box;
	
	.goods-item-left {
		margin-right: 5px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		
		.goods-radio {
			
		}
		.goods-pic {
			width: 100px;
			height: 100px;
			vertical-align: middle;
		}
	}
	.goods-item-right {
		display: flex;
		flex: 1;
		flex-direction: column;
		justify-content: space-between;
		
		.goods-name {
			font-size: 13px;
		}
		
		.goods-info-box {
			display: flex;
			justify-content: space-between;
			align-items: center;
			
			.goods-price {
				font-size: 16px;
				color: #C00000;
			}
		}
	}
}
</style>